/**
 * Copyright &copy; 2012-2014 hongsuan.pplive All rights reserved.
 */
package com.hongsuan.pplive.modules.cms.entity;

import java.util.Date;

import org.compass.annotations.Index;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.compass.annotations.Store;
import org.hibernate.validator.constraints.Length;

import com.cnjson.db.persistence.DataEntity;
import com.hongsuan.pplive.modules.cms.utils.CmsUtils;
import com.hongsuan.pplive.modules.sys.entity.User;

/**
 * 文章Entity
 * @author ThinkGem
 * @version 2013-05-15
 */
@Searchable
public class Article extends DataEntity<Article> {

    public static final String DEFAULT_TEMPLATE = "frontViewArticle";
	
	private static final long serialVersionUID = 1L;

    @SearchableId(store=Store.YES,index=Index.UN_TOKENIZED,name="id")
    private String id;
    @SearchableComponent
	private Category category;// 分类编号
    @SearchableProperty(name="title",index= Index.ANALYZED,store= Store.YES)
	private String title;	// 标题
	private String image;	// 文章图片
    @SearchableProperty(name="keywords",index= Index.ANALYZED,store= Store.YES)
	private String keywords;// 关键字
	private Integer hits;	// 点击数
	private String posid;	// 推荐位（1：首页轮播图）
    private Date startDate;
    private Date expireDate;
    private String openFlag; 	// 是否公开：0否 1是
    private String courseCode;  //对外编号
    private String videoFlag;  // 是否视频课程：0否 1是

    @SearchableComponent
	private ArticleData articleData;	//文章副表

	private Date beginDate;	// 开始时间
	private Date endDate;	// 结束时间
	
	private User user;
	
	private UserCourse userCourse;
	
	private String artisan_id;
	
	private String learn;
	
	private String myFlage = "1";
	
	private String parentId;
	
	
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	private String[] ids;
    
	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public String getMyFlage() {
		return myFlage;
	}

	public void setMyFlage(String myFlage) {
		this.myFlage = myFlage;
	}

	public String getLearn() {
		return learn;
	}

	public void setLearn(String learn) {
		this.learn = learn;
	}

	public UserCourse getUserCourse() {
		return userCourse;
	}

	public void setUserCourse(UserCourse userCourse) {
		this.userCourse = userCourse;
	}

	public String getArtisan_id() {
		return artisan_id;
	}

	public void setArtisan_id(String artisan_id) {
		this.artisan_id = artisan_id;
	}

	public Article() {
		super();
		this.hits = 0;
	}

	public Article(String id){
		this();
		this.id = id;
	}
	
	public Article(Category category){
		this();
		this.category = category;
	}

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

	public void prePersist(){
		//TODO 后续处理，暂不知有何用处
		//super.prePersist();
		articleData.setId(this.id);
	}
	
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Length(min=0, max=255)
	public String getImage() {
		return image;
	}

	public void setImage(String image) {
        this.image = image;//CmsUtils.formatImageSrcToDb(image);
	}

	@Length(min=0, max=255)
	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Integer getHits() {
		return hits;
	}

	public void setHits(Integer hits) {
		this.hits = hits;
	}

	@Length(min=0, max=10)
	public String getPosid() {
		return posid;
	}

	public void setPosid(String posid) {
		this.posid = posid;
	}

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    public String getOpenFlag() {
        return openFlag;
    }

    public void setOpenFlag(String openFlag) {
        this.openFlag = openFlag;
    }

    public String getCourseCode() {
        return courseCode;
    }

    public void setCourseCode(String courseCode) {
        this.courseCode = courseCode;
    }

    public String getVideoFlag() {
        return videoFlag;
    }

    public void setVideoFlag(String videoFlag) {
        this.videoFlag = videoFlag;
    }

    public ArticleData getArticleData() {
		return articleData;
	}

	public void setArticleData(ArticleData articleData) {
		this.articleData = articleData;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

   	public String getUrl() {
        return CmsUtils.getUrlDynamic(this);
   	}

   	public String getImageSrc() {
        return CmsUtils.formatImageSrcToWeb(this.image);
   	}
}


